package com.zhike.service.messages;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.index.Index;
import org.springframework.data.mongodb.core.index.IndexOperations;
import org.springframework.stereotype.Service;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class IndexCreatorService {

    @Autowired
    private MongoTemplate mongoTemplate;

    @PostConstruct
    public void createSessionIdIndex() {
        Index index = new Index()
                .on("sessionId", Direction.ASC)
                .on("timestamp", Direction.ASC)
                .on("senderUid", Direction.ASC)
                .on("groupId", Direction.ASC)
                .on("fp", Direction.ASC);
        mongoTemplate.indexOps("history_message").ensureIndex(index);
        log.info("创建了sessionId索引");
    }
}
